package com.yuncheng.oaApi.controller;

import java.util.*;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.vo.HttpResult;
import com.yuncheng.annotation.AutoLog;
import com.yuncheng.utils.I18nUtil;
import com.yuncheng.common.base.controller.BaseController;
import com.yuncheng.oaApi.entity.OaProcessBusiness;
import com.yuncheng.oaApi.service.IOaProcessBusinessService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;

/**
 * @Description: 流程业务主表
 * @Author: yuncheng
 * @Date: 2023-10-23
 * @Version: V1.0
 */
@Api(tags = "流程业务主表接口")
@RestController
@RequestMapping("/api/oa/oaProcessBusiness")
public class OaProcessBusinessController extends BaseController<OaProcessBusiness, IOaProcessBusinessService> {

    private static final Logger log = LoggerFactory.getLogger(OaProcessBusinessController.class);

    @Resource
    private IOaProcessBusinessService oaProcessBusinessService;

    /**
     * 分页列表查询
     *
     * @param oaProcessBusiness
     * @param pageNo
     * @param pageSize
     * @param
     * @return
     */
    @AutoLog(value = "流程业务主表-分页列表查询")
    @ApiOperation(value = "流程业务主表-分页列表查询")
    @GetMapping(value = "/list")
    public HttpResult<?> queryPageList(OaProcessBusiness oaProcessBusiness, @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LambdaQueryWrapper<OaProcessBusiness> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(StringUtils.isNotBlank(oaProcessBusiness.getFlcmb()),OaProcessBusiness::getFlcmb,oaProcessBusiness.getFlcmb());

        Page<OaProcessBusiness> page = new Page<>(pageNo, pageSize);

        IPage<OaProcessBusiness> pageList = oaProcessBusinessService.page(page, queryWrapper);

        return HttpResult.ok(pageList);
    }



    /**
     * 添加
     *
     * @param oaProcessBusiness
     * @return
     */
    @AutoLog(value = "流程业务主表-添加")
    @ApiOperation(value = "流程业务主表-添加")
    //@RequiresPermissions("oa:OaProcessBusiness:add")
    @PostMapping(value = "/add")
    public HttpResult<?> add(@RequestBody OaProcessBusiness oaProcessBusiness) {
        HttpResult<String> result = new HttpResult(true);
        oaProcessBusinessService.save(oaProcessBusiness);
        result.setResult(oaProcessBusiness.getId());
        result.setMessage(I18nUtil.message("save.success"));
        return result;
    }

    /**
     * 编辑
     *
     * @param oaProcessBusiness
     * @return
     */
    @AutoLog(value = "流程业务主表-编辑")
    @ApiOperation(value = "流程业务主表-编辑")
    //@RequiresPermissions("oa:OaProcessBusiness:edit")
    @PutMapping(value = "/edit")
    public HttpResult<?> edit(@RequestBody OaProcessBusiness oaProcessBusiness) {
        oaProcessBusinessService.updateById(oaProcessBusiness);
        return HttpResult.ok(I18nUtil.message("update.success"));
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程业务主表-通过id删除")
    @ApiOperation(value = "流程业务主表-通过id删除")
    //@RequiresPermissions("oa:OaProcessBusiness:delete")
    @DeleteMapping(value = "/delete")
    public HttpResult<?> delete(@RequestParam("id") String id) {
        oaProcessBusinessService.removeById(id);
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "流程业务主表-批量删除")
    @ApiOperation(value = "流程业务主表-批量删除")
    //@RequiresPermissions("oa:OaProcessBusiness:delete")
    @DeleteMapping(value = "/deleteBatch")
    public HttpResult<?> deleteBatch(@RequestParam("ids") String ids) {
        oaProcessBusinessService.removeByIds(Arrays.asList(ids.split(",")));
        return HttpResult.ok(I18nUtil.message("delete.success"));
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @AutoLog(value = "流程业务主表-通过id查询")
    @ApiOperation(value = "流程业务主表-通过id查询")
    @GetMapping(value = "/queryById")
    public HttpResult<?> queryById(@RequestParam("id") String id) {
        OaProcessBusiness oaProcessBusiness = oaProcessBusinessService.getById(id);
        return HttpResult.ok(oaProcessBusiness);
    }


}
